package com.iursp.service.role;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iursp.conf.aop.LoggerManage;
import com.iursp.domain.model.role.Role;
import com.iursp.mapper.role.AuthRoleMapper;
import com.iursp.utils.common.LogUtils;

import javassist.NotFoundException;

@Service
public class AuthRoleService {
	
	@Autowired
	private AuthRoleMapper roleMapper;

	public List<Role> queryAllRole() {
		return roleMapper.queryAllRole();
	}

	public Role getRoleByRefid(String refid) {
		return roleMapper.selectByPrimaryKey(refid);
	}

	public void updateRole(Role role) {
		roleMapper.updateByPrimaryKey(role);
	}

	public void addRole(Role role) {
		roleMapper.insert(role);
	}

	public void deleteRoleByRefid(String refid) {
		roleMapper.deleteByPrimaryKey(refid);
	}

	@LoggerManage(logStr = "查询角色根据用户")
	public String selectByUserRefid(String refid) {
		return roleMapper.selectByUserRefid(refid).stream().map(e -> e.getRoleCode()).collect(Collectors.joining(","));
	}

}
